//
//  TabViewController.swift
//  ClothAccess
//
//  Created by Wei Hua on 2021/2/3.
//

import Foundation

class TabViewObservable: ObservableObject {
    
    @Published var tabItemData: [tabItem] = Data_TabView            // item 数据组
    @Published var navigationBarHiddenStatus: Bool = true           // NavigationBar 隐藏状态 默认隐藏
    @Published var selected: Int = 0                                // 选中 item 中的视图，默认选择第一个
    
    static let shared = TabViewObservable()
    
    func setSelected(_ tab: tabItem)-> Void {
        for (index, aTab) in tabItemData.enumerated() {
            if aTab.id == tab.id {
                self.selected = index
                tabItemData[index].showTxt = true
            } else {
                tabItemData[index].showTxt = false
            }
        }
        self.setNavigationBarHiddenStatus()
    }
    
    func getItem() -> tabItem {
        tabItemData[selected]
    }
    
    func setNavigationBarHiddenStatus() -> Void {
        self.navigationBarHiddenStatus = self.tabItemData[self.selected].hiddenNavigation
    }
}
